﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Data.DataModel
{
    /// <summary>
    /// Property Set Class
    /// </summary>
    public class PropertySet
    {
        #region Constructor
        public PropertySet()
        {
        }

        public PropertySet(String name, string type, int size)
        {
            this.name = name;
            SetType(type);
            this.size = size;
        }

        public PropertySet(string property)
        {
            string[] propertySet = property.Split(';');
            Array.FindAll<string>(propertySet, delegate(string content)
            {
                if (content.Contains("Name="))
                {
                    this.name = content.Split('=')[1];
                }
                else if(content.Contains("Type="))
                {
                    this.type = Type.GetType(content.Split('=')[1]);
                }
                else if(content.Contains("Size="))
                {
                    this.size = int.Parse(content.Split('=')[1]);
                }
                else if (content.Contains("Primary="))
                {
                    this.primaryKey = bool.Parse(content.Split('=')[1]);
                }
                return true;
            });
        }

        #endregion

        #region Property
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private Type type;

        public Type Type
        {
            get { return type; }
            set { type = value; }
        }

        private int size;

        public int Size
        {
            get { return size; }
            set { size = value; }
        }

        private bool primaryKey = false;

        public bool PrimaryKey
        {
            get { return primaryKey; }
            set { primaryKey = value; }
        }

        #endregion

        /// <summary>
        /// Set PropertyType by string
        /// Should be full name of type
        /// </summary>
        /// <param name="type">Full name of type</param>
        /// <example>
        /// PropertSet prop = new PropertySet():
        /// SetType("System.Double");
        /// </example>
        public void SetType(string type)
        {
            this.type = Type.GetType(type);
        }
    }
}
